package br.com.netomarin.bundesliga.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.com.netomarin.bundesliga.model.MatchModel;
import br.com.netomarin.bundesliga.persistence.Match;

public class DisproveMatchServlet extends HttpServlet {

	private static final long serialVersionUID = 3647005029265976047L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		String challengedMatch = req.getParameter("match");

		Match cm = MatchModel.loadMatchByKey(challengedMatch);
		PrintWriter w = resp.getWriter();

		w.write("<html>");
		w.write("<head></head>");
		w.write("<body>");

		w.write("<p>A partida que voc&ecirc; est&aacute; desafiando &eacute;:");
		w.write("<br>" + cm.getHomeP1());
		if (cm.getHomeP2() != null)
			w.write(" / " + cm.getHomeP2());
		w.write(" (" + cm.getHomeTeam() + ") " + cm.getScoreHomeTeam() + " X ");
		w.write(cm.getScoreVisitorTeam() + " " + cm.getVisitorP1());
		if (cm.getVisitorP2() != null)
			w.write(" / " + cm.getVisitorP2());
		w.write(" (" + cm.getVisitorTeam() + ")");

		w.write("<p>Informe os dados que voc&ecirc; acha que s&atilde;o os corretos:"
				+ "<br>Obs.: Os dados ser&atilde;o enviados para confirma&ccedil;&atilde;o dos advers&aacute;rios."
				+ "E caso eles n&atilde;o concordem, a partida ser&aacute; enviada para os moderadores."
				+ "<form action=\"notifyChallengedMatch\" method=\"POST\">"
				+ "<input type=\"hidden\" name=\"challenged_match\" value=\""
				+ challengedMatch
				+ "\">"
				+ "<p>Quem &eacute; voc&ecirc;?"
				+ "<br><input type=\"text\" name=\"notifier\">"
				+ "<table>"
				+ "<tr>"
				+ "<th>Time 1</th>"
				+ "<th>P1 Time 1</th>"
				+ "<th>P2 Time 1</th>"
				+ "<th>Gols Time 1</th>"
				+ "<th>&nbsp;X&nbsp;</th>"
				+ "<th>Gols Time 2</th>"
				+ "<th>Time 2</th>"
				+ "<th>P1 Time 2</th>"
				+ "<th>P2 Time 2</th>"
				+ "</tr>"
				+ "<tr>"
				+ "<td><input type=\"text\" name=\"home_team\"></td>"
				+ "<td><input type=\"text\" name=\"home_team_p1\"></td>"
				+ "<td><input type=\"text\" name=\"home_team_p2\"></td>"
				+ "<td><input type=\"text\" name=\"score_home_team\"></td>"
				+ "<td><b>&nbsp;X&nbsp;</b></td>"
				+ "<td><input type=\"text\" name=\"score_visitor_team\"></td>"
				+ "<td><input type=\"text\" name=\"visitor_team\"></td>"
				+ "<td><input type=\"text\" name=\"visitor_team_p1\"></td>"
				+ "<td><input type=\"text\" name=\"visitor_team_p2\"></td>"
				+ "</tr>"
				+ "</table>"
				+ "<p><input type=radio name=\"match_type\" value=\"league\" checked=\"checked\">Partida Bundesliga<br />"
				+ "<input type=radio name=\"match_type\" value=\"champ\">Partida de campeonato<br />"
				+ "<center><input type=\"submit\" value=\"Enviar\"></center>"
				+ "</form>" + "<body></html>");

	}
}